import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
//更改昵称
import { NewNamePage } from '../new-name/new-name';
import { Https } from '../../app/http.service';
import { BankcardPage } from '../bankcard/bankcard';
//我的银行卡

//我的地址
import { AddressPage } from '../address/address';
import { ChangePhonePage } from '../change-phone/change-phone';
//修改手机号
/**
 * Generated class for the UserinfoPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-userinfo',
  templateUrl: 'userinfo.html',
})
export class UserinfoPage {
	aplyUrl: string = new Https().Url + "act=goods&op=app_get_user_info";
	user_name:string = "未登录";
	user_phone:string;
	user_pic: string = "./assets/imgs/user.png";
	constructor(public navCtrl: NavController, public navParams: NavParams) {
		if (localStorage.getItem("token") != null && localStorage.getItem("mid") != null && localStorage.getItem("loginState") == '0'){
			fetch(this.aplyUrl, {
				method: 'post',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				body: "mid=" + localStorage.getItem("mid") + "&token=" + localStorage.getItem("token"),
			}).then((response) => {
				response.text().then((con) => {
					let user = JSON.parse(con);
					this.user_name =user['user_name']
					this.user_phone = user['user_phone']
					this.user_pic = localStorage.getItem("userPic")
				}).catch((err) => {
					console.log(err)
				})

			}).catch((err) => {
				console.log(err)
			})
		}
		
	}

	ionViewDidLoad() {
		console.log('ionViewDidLoad UserinfoPage'); 
		
	}
	changePhone(){
		this.navCtrl.push(ChangePhonePage)
	}
	changeName(){
		this.navCtrl.push(NewNamePage)
	}
	bankCard(){
		this.navCtrl.push(BankcardPage)
	}
	address(){
		this.navCtrl.push(AddressPage)
	}
}
